package com.spring.until;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;


public class IdUtil {
    final static private String host = "https://idenauthen.market.alicloudapi.com";
    final static private String path = "/idenAuthentication";
    final static private String method = "POST";
    final static private String appcode = "3e0ad5b13aba4a73aed69ffba5a8e48c";

    static public boolean post(String id,String name){
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("idNo", id);
        bodys.put("name", name);

        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            String str = EntityUtils.toString(response.getEntity());
            Map m = JsonUtil.getMap(str) ;
            System.out.println(str);
            if(m.get("respCode").equals("0000")){
                return  true ;
            }else{
                return  false ;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false ;
        }
    }
}
